package com.zhang.common.model;

import lombok.Data;

import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * 用户商品推荐分析模型
 *
 * @author hongmizfb
 * @date 2024/04/25
 */

public class SkuRecommendModel {

    /**
     * 用户关注的分类，最多长度为3
     */
    List<Long> categoryIds;

    /**
     * 用户关注的搜索内容，最多长度为10
     */
    private List<String> searchWord;

    /**
     * 品牌ids
     */
    private List<Long> brandIds;

    public List<Long> getCategoryIds() {
        return categoryIds;
    }

    public void setCategoryIds(List<Long> categoryId) {
        categoryId = categoryId.stream().distinct().collect(Collectors.toList());
//        如果大于三，则只保留最后三个元素
        if (categoryId.size() > 3) {
            List<Long> longs = categoryId.subList(categoryId.size() - 3, categoryId.size());
            this.categoryIds = longs;
        } else {
            this.categoryIds = categoryId;
        }
    }

    public List<String> getSearchWord() {
        return searchWord;
    }

    public void setSearchWord(List<String> searchWord) {
        searchWord = searchWord.stream().distinct().filter(item -> !Objects.equals(item, "")).collect(Collectors.toList());
        if (searchWord.size() > 3) {
            this.searchWord = searchWord.subList(searchWord.size() - 3, searchWord.size());
        } else {
            this.searchWord = searchWord;
        }
    }

    public List<Long> getBrandIds() {
        return brandIds;
    }

    public void setBrandIds(List<Long> brandIds) {
        brandIds = brandIds.stream().distinct().collect(Collectors.toList());
        if (brandIds.size() > 5) {
            List<Long> longs = brandIds.subList(brandIds.size() - 5, brandIds.size());
            this.brandIds = longs;
        } else {
            this.brandIds = brandIds;
        }
    }


    @Override
    public String toString() {
        return "SkuRecommendModel{" +
                "categoryId=" + categoryIds +
                ", searchWord=" + searchWord +
                ", brandIds=" + brandIds +
                '}';
    }
}
